home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1993 / Internet Info CD-ROM (Walnut Creek) (1993).iso / networking / terms / kermit / b / ckcplm.doc < prev    next >
Encoding:
Text File  |  1993-06-30  |  59.6 KB  |  1,428 lines

  1. CKAPLM.DOC    The C-Kermit Version 5A Interface Definition            June 1993
  2.  
  3.                  PROGRAM LOGIC MANUAL
  4.  
  5. Author: F. da Cruz, Columbia University
  6. E-Mail: fdc@watsun.cc.columbia.edu, FDCCU@CUVMA.BITNET
  7.  
  8.   Copyright (C) 1985, 1993, Trustees of Columbia University in the City of New
  9.   York.  The C-Kermit software may not be, in whole or in part, licensed or
  10.   sold for profit as a software product itself, nor may it be included in or
  11.   distributed with commercial products or otherwise distributed by commercial
  12.   concerns to their clients or customers without written permission of the
  13.   Office of Kermit Development and Distribution, Columbia University.  This
  14.   copyright notice must not be removed, altered, or obscured.
  15.  
  16. Last update: Tue Jun 29 12:26:37 1993
  17. As of edit:  189
  18.  
  19.  
  20. DOCUMENTATION
  21.  
  22. C-Kermit 5A is documented in the book "Using C-Kermit" by Frank da Cruz
  23. and Christine M. Gianone, Digital Press, Burlington, MA, USA.  Digital
  24. Press ISBN: 1-55558-108-0; Prentice-Hall ISBN: 0-13-037490-3.  Price: US
  25. $34.95.  In USA, call DECdirect at 1-800-344-4825, refer to order number
  26. EY-J896E-DP.  Available: January 1993.
  27.  
  28.  
  29. INTRODUCTION
  30.  
  31. This is an attempt at describing the relationship among the modules and
  32. functions of C-Kermit version 5A.  Before reading this file, please read the
  33. file CKAAAA.HLP for an overview of C-Kermit file naming conventions.
  34.  
  35. C-Kermit is designed to be portable to any kind of computer that has a C
  36. compiler.  The source code is broken into many files that are grouped
  37. according to their function.  There are several major groups: 1 (the protocol
  38. kernel), 2 (the user interface), 3 (system-dependent primitives), 4 (network
  39. support), and 5 (formatted screen support).
  40.  
  41. FILES
  42.  
  43. C-Kermit source files begin with the two letters CK (lowercase on UNIX
  44. systems, uppercase on most others).  The third character denotes something
  45. about the function group and the expected level of portability.  See the file
  46. CKAAAA.HLP for details of file naming conventions and organization.
  47.  
  48. One hint before proceeding: functions are scattered all over the ckc*.c
  49. and ckuu*.c modules, where function size has begun to take precedence over
  50. the desirability of grouping related functions together, the aim being to
  51. keep any particular module from growing disproportionately large.  The easiest
  52. way (in UNIX) to find out what source file a given function is defined in is
  53. like this (where the desired function is foo()...):
  54.  
  55.   grep ^foo ck*.c
  56.  
  57. This works because the coding convention has been to make function names
  58. always start on the left margin, for example:
  59.  
  60. static char *
  61. foo(x,y) int x, y; {
  62.   ...
  63. }
  64.  
  65.  
  66. SOURCE CODE PORTABILITY GUIDE
  67.  
  68. When writing code for C-Kermit, please stick to the following coding
  69. conventions to ensure portability to small or old C compilers and linkers:
  70.  
  71. . Keep variable, function, and symbol names unique within 6 characters.
  72. . Don't use the #if preprocessor construction, only use #ifdef.
  73. . Put tokens after #endif in comment brackets, e.g. #endif /* FOO */.
  74. . Don't use logical operators in preprocessor constructions.
  75. . Always cast strlen() to int, e.g. "if ((int)strlen(foo) < x)...".
  76. . Any variable whose value might exceed 16383 should be long.
  77. . Avoid the construction *++p -- the order of evaluation varies.
  78. . Reportedly, some compilers even mess up with *(++p).
  79. . Avoid huge switch() statements with many cases.
  80. . Don't make character-string constants longer than about 250.
  81. . Don't depend on '\r' being carriage return.
  82. . Don't depend on '\n' being linefeed.
  83. . Don't depend on '\r' and '\n' being different (e.g. in switch() statements).
  84. . Remember, in Sys V, signals must always be re-armed to be used again.
  85.  
  86. (many, many more...  This section needs massive filling in.)
  87.  
  88. CONTENTS:
  89.  
  90.   GROUP 1    System-independent file transfer protocol
  91.   GROUP 1.5  Character set translation
  92.   GROUP 2    User Interface
  93.   GROUP 3    File & communications i/o and other system dependencies
  94.   GROUP 4    Network support
  95.   GROUP 5    Formatted screen support
  96.  
  97. GROUP 1:
  98.  
  99. The Kermit protocol kernel.  The filenames start with CKC.  C means that these
  100. files are supposed to be totally portable C, and are expected to compile
  101. correctly on any operating system.  "Portable" does not mean the same as as
  102. "ANSI" -- these modules must compile on 10- and 15-year old computers, with C
  103. preprocessors, compilers, and/or linkers that have all sorts of restrictions.
  104. The group 1 modules do not include any header files other than those that
  105. come with Kermit itself.  They do not contain any library calls (like printf)
  106. or any system calls (like open, close, read, write).  Files:
  107.  
  108.   CKCSYM.H - For use by C compilers that don't allow -D on the command line.
  109.   CKCASC.H - ASCII character symbol definitions.
  110.   CKCDEB.H - Originally, debugging definitions.  Now this file also contains
  111.          all compiler-dependent definitions (such as typedefs) that must
  112.          be shared by all modules in all groups.
  113.   CKCKER.H - Kermit protocol symbol definitions.
  114.   CKCNET.H - Network-related symbol definitions.
  115.   CKCXLA.H - Character-set-related symbol definitions.
  116.  
  117.   CKCMAI.C - The main program.  This module contains the declarations of all
  118.   the protocol-related global variables that are shared among the other
  119.   modules.  If you want to imbed Kermit protocol within another program,
  120.   you'll have to copy the declarations from ckcmai.c into your program.
  121.  
  122.   CKCPRO.W - The protocol module itself, written in "wart", a lex-like
  123.   preprocessor that is distributed with Kermit under the name CKWART.C.
  124.  
  125.   CKCFN*.C - The protocol support functions used by the protocol module.
  126.  
  127. Group 1 modules may call upon functions from Group 3 modules, but not from
  128. Group 2 modules (with the single exception that the main program invokes the
  129. user interface, which is in Group 2).  (This last assertion is really only a
  130. conjecture.)
  131.  
  132. GROUP 1.5
  133.  
  134. Character set translation tables and functions.  Used by the Group I protocol
  135. modules, but may be specific to different computers.  (So far, all character
  136. character sets supported by C-Kermit are supported in CKUXLA.C and CKUXLA.H,
  137. including Macintosh and IBM character sets).
  138.  
  139.   CKCXLA.H - Character-set definitions usable by all versions of C-Kermit.
  140.   CK?XLA.H - Character-set definitions for computer "?", e.g. U for UNIX.
  141.  
  142.   CK?XLA.C - Character-set translation tables and functions for computer "?",
  143.   For example, CKUXLA.C for UNIX, CKMXLA.C for Macintosh.  So far, these are
  144.   the only two such modules.  The UNIX module is used for all versions of
  145.   C-Kermit except the Macintosh version.
  146.  
  147.   Used for file transfer (SEND, RECEIVE, GET, REMOTE, etc), TRANSMIT,
  148.   CONNECT, etc.
  149.  
  150.   Here's how to add a new file character set.  Assuming it is based on the
  151.   Roman (Latin) alphabet.  Let's call it "Barbarian".  First, in CK?XLA.H,
  152.   add a definition for FC_BARBA (8 chars maximum length) and increase
  153.   MAXFCSETS by 1.  Then, in CK?XLA.C:
  154.  
  155.   . Add a barbarian entry into the fcsinfo array.
  156.   . Add a "barbarian" entry to file character set keyword table, fcstab.
  157.   . Add a "barbarian" entry to terminal character set keyword table, ttcstab.
  158.   . Add a translation table from Latin-1 to barbarian: yl1ba[].
  159.   . Add a translation table from barbarian to Latin-1: ybal1[].
  160.   . Add a translation function from Barbarian to ASCII: xbaas().
  161.   . Add a translation function from Barbarian to Latin-1: xbal1().
  162.   . Add a translation function from Latin-1 to Barbarian: xl1ba().
  163.   .  etc etc for each transfer character set...
  164.   . Add translation function pointers to the xls and xlr tables.
  165.  
  166.   Other translations involving Barbarian (e.g. from Barbarian to
  167.   Latin-Cyrillic) are performed through these tables and functions.  See
  168.   CKUXLA.H and CKUXLA.C for extensive examples.
  169.  
  170. GROUP 2:
  171.  
  172. The user interface.  This is the code that communicates with the user, gets
  173. her commands, informs her of the results.  It may be command-line oriented,
  174. interactive prompting dialog, menus and arrow keys, windows and mice, speech
  175. recognition, telepathy, etc.  The user interface has three major functions:
  176.  
  177. 1. Sets the parameters for the file transfer and then start it.  This is done
  178. by setting certain (many) global variables, such as the protocol machine start
  179. state, the file specification, file type, communication parameters, packet
  180. length, window size, character set, etc.
  181.  
  182. 2. Displays messages on the user's screen during the file transfer, using the
  183. screen() function, which is called by the group-1 modules.
  184.  
  185. 3. Executes any commands directly that do not require Kermit protocol, such
  186. as the CONNECT command, local file management commands, parameter-setting
  187. commands, etc.
  188.  
  189. If you plan to imbed the Group 1 files into a program with a different user
  190. interface, your interface must supply an appropriate screen() function, plus a
  191. couple related ones like chkint() and intmsg() for handling keyboard (or
  192. mouse, etc) interruptions during file transfer.  The best way to find out
  193. about this is to link all the C-Kermit modules together except the CKUU*.O
  194. and CKUCON.O modules, and see which missing symbols turn up.
  195.  
  196. C-Kermit's character-oriented user interface (as opposed to the Macintosh
  197. version's graphical user interface) consists of the following modules.
  198. C-Kermit can be built with an interactive command parser, a
  199. command-line-option-only parser, or (most commonly) both:
  200.  
  201.   CKUUSR.H - Definitions of symbols used in Kermit's commands.
  202.  
  203.   CKUUSR.H, CKUUSR.C, CKUUS2.C, CKUUS3.C, CKUUS4.C, CKUUS5.C, ... -
  204.   Kermit's interactivbe command parser, including the script programming
  205.   language.
  206.  
  207.   CKUUSY.C - The command-line-option parser.
  208.  
  209.   CKUUSX.C - Functions that are common to both the interactive and 
  210.   command-line parsers.
  211.  
  212.   CKUCMD.H, CKUCMD.C - The command parsing primitives used by the
  213.   interactive command parser to parse keywords, numbers, filenames, etc,
  214.   and to give help, complete fields, supply defaults, allow abbreviations
  215.   and editing, etc.  This package is totally independent of Kermit, but
  216.   does depend on the Group 3 functions.
  217.  
  218.   CKUVER.H - Version heralds for different implementations.
  219.  
  220.   CKUSCR.C - The (old, uucp-like) SCRIPT command.
  221.   CKUDIA.C - The DIAL command.
  222.  
  223.   CK?CON.C - The CONNECT command.  Terminal connection, and in some cases
  224.              (Macintosh, OS/2) also terminal emulation.
  225.  
  226. For other implementations, the files may, and probably do, have different
  227. names.  For example, the Macintosh graphical user interface filenames start
  228. with CKM.  OS/2 uses the CKUCMD and CKUUS* modules, but has its own CONNECT
  229. command in CKOCON.C.  And so on.
  230.  
  231. Here is a brief description of C-Kermit's "user interface interface", from 
  232. CKUUSR.C:
  233.  
  234. The ckuus*.c modules depend on the existence of C library features like fopen,
  235. fgets, feof, (f)printf, argv/argc, etc.  Other functions that are likely to
  236. vary among Unix implementations -- like setting terminal modes or interrupts
  237. -- are invoked via calls to functions that are defined in the system-
  238. dependent modules, ck?[ft]io.c.  The command line parser processes any
  239. arguments found on the command line, as passed to main() via argv/argc.  The
  240. interactive parser uses the facilities of the cmd package (developed for this
  241. program, but usable by any program).  Any command parser may be substituted
  242. for this one.  The only requirements for the Kermit command parser are these:
  243.  
  244. 1. Set parameters via global variables like duplex, speed, ttname, etc.  See
  245.    ckmain.c for the declarations and descriptions of these variables.
  246.  
  247. 2. If a command can be executed without the use of Kermit protocol, then
  248.    execute the command directly and set the variable sstate to 0.  Examples
  249.    include 'set' commands, local directory listings, the 'connect' command.
  250.  
  251. 3. If a command requires the Kermit protocol, set the following variables:
  252.  
  253.    sstate                             string data
  254.      'x' (enter server mode)            (none)
  255.      'r' (send a 'get' command)         cmarg, cmarg2
  256.      'v' (enter receive mode)           cmarg2
  257.      'g' (send a generic command)       cmarg
  258.      's' (send files)                   nfils, cmarg & cmarg2 OR cmlist
  259.      'c' (send a remote host command)   cmarg
  260.  
  261.    cmlist is an array of pointers to strings.
  262.    cmarg, cmarg2 are pointers to strings.
  263.    nfils is an integer.
  264.  
  265.    cmarg can be a filename string (possibly wild), or
  266.       a pointer to a prefabricated generic command string, or
  267.       a pointer to a host command string.
  268.    cmarg2 is the name to send a single file under, or
  269.       the name under which to store an incoming file; must not be wild.
  270.       If it's the name for receiving, a null value means to store the
  271.       file under the name it arrives with.
  272.    cmlist is a list of nonwild filenames, such as passed via argv.
  273.    nfils is an integer, interpreted as follows:
  274.      -1: filespec (possibly wild) in cmarg, must be expanded internally.
  275.       0: send from stdin (standard input).
  276.      >0: number of files to send, from cmlist.
  277.  
  278. The screen() function is used to update the screen during file transfer.
  279. The tlog() function writes to a transaction log (if TLOG is defined).
  280. The debug() function writes to a debugging log (if DLOG is defined).
  281. The intmsg() and chkint() functions provide the user i/o for interrupting
  282. file transfers.
  283.  
  284. GROUP 3:
  285.  
  286. System-dependent function definitions.  All the Kermit modules, including the
  287. command package, call upon these functions, which are designed to provide
  288. system-independent primitives for controlling and manipulating devices and
  289. files.  For UNIX, these functions are defined in the files CKUFIO.C (files)
  290. and CKUTIO.C (communication devices).  For VMS, the files are CKVFIO.C and
  291. CKVTIO.C.  For OS/2, CKOFIO.C, CKOTIO.C.  It doesn't really matter what the
  292. filenames are, except for Kermit distribution purposes (grouping related files
  293. together alphabetically), only that each function is provided with the name
  294. indicated, observes the same calling and return conventions, and has the same
  295. type.
  296.  
  297. The Group 3 modules contain both functions and global variables that are
  298. accessed by modules in the other groups.  These are now described.  Changes
  299. since version 4E of C-Kermit are flagged by the symbol *NEW* (use grep).
  300.  
  301. (By the way, I got this list by linking all the C-Kermit modules together
  302. except CKUTIO and CKUFIO.  These are the symbols that ld reported as undefined)
  303.  
  304. A. Variables:
  305.  
  306. char *DELCMD;
  307.   Pointer to string containing command for deleting files.
  308.   Example: char *DELCMD = "rm -f ";  (UNIX)
  309.   Example: char *DELCMD = "delete "; (VMS)
  310.   Note trailing space.  Filename is concatenated to end of this string.
  311.  
  312. char *DIRCMD;
  313.   Pointer to string containing command for listing files when a filespec
  314.   is given.
  315.   Example: char *DIRCMD = "/bin/ls -l "; (UNIX)
  316.   Example: char *DIRCMD = "directory ";  (VMS)
  317.   Note trailing space.  Filename is concatenated to end of this string.
  318.  
  319. char *DIRCM2;   *NEW*
  320.   Pointer to string containing command for listing files when a filespec
  321.   is not given.  (currently not used, handled in another way.)
  322.   Example: char *DIRCMD = "/bin/ls -ld *";
  323.   
  324. char *PWDCMD;
  325.   Pointer to string containing command to display current directory.
  326.   Example: char *PWDCMD = "pwd ";
  327.  
  328. char *SPACMD;
  329.   Pointer to command to display free disk space in current device/directory. 
  330.   Example: char *SPACMD = "df .";
  331.  
  332. char *SPACM2;
  333.   Pointer to command to display free disk space in another device/directory. 
  334.   Example: char *SPACM2 = "df ";
  335.   Note trailing space.  Device or directory name is added to this string.
  336.  
  337. char *TYPCMD;
  338.   Pointer to command for displaying the contents of a file.
  339.   Example: char *TYPCMD = "cat ";
  340.   Note trailing space.  Device or directory name is added to this string.
  341.  
  342. char *WHOCMD;
  343.   Pointer to command for displaying logged-in users.
  344.   Example: char *WHOCMD = "who ";
  345.   Note trailing space.  Specific user name may be added to this string.
  346.  
  347. int backgrd = 0;
  348.   Flag for whether program is running in foreground (0) or background
  349.   (nonzero).  Background operation implies that screen output should not be
  350.   done and that all errors should be fatal.
  351.  
  352. int ckxech;
  353.   Flag for who is to echo console typein:  
  354.   1 - The program (system is not echoing).
  355.   0 - The system, front end, terminal, etc (not this program)
  356.  
  357. char *ckxsys;
  358.   Pointer to string that names the computer and operating system.
  359.   Example: char *ckxsys = " NeXT Mach 1.0";
  360.   Tells what computer system ckxv applies to.
  361.   In UNIX Kermit, this variable is also used to print the program herald, 
  362.   and in the SHOW VERSION command.
  363.  
  364. char *ckxv;
  365.   Pointer to version/edit info of ck?tio.c module.
  366.   Example: char *ckxv = "Unix tty I/O, 5A(061), 13 Mar 90";
  367.   Used by SHOW VERSION command.
  368.  
  369. char *ckzsys;
  370.   Like ckxsys, but briefer.
  371.   Example: char *ckzsys = " 4.3 BSD";
  372.   Tells what computer system ckzv applies to.
  373.   Used by the SHOW VERSION command.
  374.  
  375. char *ckzv;
  376.   Pointer to version/edit info of ck?fio.c module.
  377.   Example: char *ckzv = "Unix file support, 5A(041) 27 Mar 90";
  378.   Used by SHOW VERSION command.
  379.  
  380. int dfflow;
  381.   Default flow control.
  382.   0 = none, 1 = Xon/Xoff.
  383.   Set to by group 3 module.
  384.   Used by ckcmai.c to initialize flow control variable.
  385.  
  386. int dfloc;
  387.   Default location.
  388.   0 = remote, 1 = local.
  389.   Set by group 3 module.
  390.   Used by ckcmai.c to initialize local variable.  Used in various places in
  391.   the user interface.
  392.  
  393. int dfprty;
  394.   Default parity.
  395.   0 = none, 'e' = even, 'o' = odd, 'm' = mark, 's' = space.
  396.   Set by Group 3 module.  Used by ckcmai.c to initialize parity variable.
  397.  
  398. char *dftty;
  399.   Default communication device.
  400.   Set by group 3 module.  Used in many places.
  401.   This variable should be initialized the the symbol CTTNAM, which is defined
  402.   in ckcdeb.h, e.g. as "/dev/tty" for UNIX, "TT:" for VAX/VMS, etc.
  403.   Example: char *dftty = CTTNAM;
  404.  
  405. char *mtchs[];  *NEW*
  406.   Array of string pointers to filenames that matched the most recent
  407.   wildcard match, i.e. the most recent call to zxpand().  Used (at least) by
  408.   command parsing package for partial filename completion.
  409.  
  410. int tilde_expand;  *NEW*
  411.   Flag for whether to attempt to expand leading tildes in directory names
  412.   (used in UNIX only, and then only when the symbol DTILDE is defined.
  413.  
  414. int ttnproto;  *NEW*
  415.   The protocol being used to communicate over a network device.  Values are
  416.   defined in ckcnet.h.  Example: NP_TELNET is network protocol "telnet".
  417.  
  418. int maxnam;  *NEW*
  419.   The maximum length for a filename, exclusive of any device or directory
  420.   information, in the format of the host operating system.
  421.  
  422. int maxpath;  *NEW*
  423.   The maximum length for a fully specified filename, including device 
  424.   designator, directory name, network node name, etc, in the format of
  425.   the host operating system, and including all punctuation.
  426.  
  427. B. Functions.
  428.  
  429. These are divided into three categories: file-related functions (B.1),
  430. communication functions (B.2), and miscellaneous functions (B.3).
  431.  
  432. B.1.  File-related functions.
  433.  
  434. In most implementations, these are collected together into a module called
  435. CK?FIO.c, where ? = U (UNIX), V (VMS), O (OS/2), etc (see CKAAAA.HLP).  To be
  436. totally system-independent, C-Kermit maintains its own file numbers, and
  437. provides the functions described in this section to deal with the files
  438. associated with them.  The file numbers are referred to symbolically, and are
  439. defined as follows in CKCKER.H:
  440.  
  441. #define ZCTERM      0            /* Console terminal */
  442. #define ZSTDIO      1        /* Standard input/output */
  443. #define ZIFILE        2        /* Current input file for SEND command */
  444. #define ZOFILE      3            /* Current output file for RECEIVE command */
  445. #define ZDFILE      4            /* Current debugging log file */
  446. #define ZTFILE      5            /* Current transaction log file */
  447. #define ZPFILE      6            /* Current packet log file */
  448. #define ZSFILE      7        /* Current session log file */
  449. #define ZSYSFN        8        /* Input from a system function (pipe) */
  450. #define ZRFILE      9           /* Local file for READ command */  (NEW)
  451. #define ZWFILE     10           /* Local file for WRITE command */ (NEW)
  452. #define ZNFILS     11            /* How many defined file numbers */
  453.  
  454. In the descriptions below, fn refers to a filename, and n refers to one of
  455. these file numbers.  Functions are of type int unless otherwise noted, and are
  456. listed alphabetically.
  457.  
  458. chkfn(n) int n;
  459.   Checks the file number n.  Returns:
  460.   -1: File number n is out of range
  461.    0: n is in range, but file is not open
  462.    1: n in range and file is open
  463.  
  464. iswild(filspec) char *filespec; *NEW*
  465.   Checks if the file specification is "wild", i.e. contains metacharacters
  466.   or other notations intended to match multiple filenames.  Returns:
  467.    0: not wild
  468.    1: wild
  469.  
  470. zchdir(dirnam) char *dirnam;
  471.   Change current or default directory to the one given in dirnam.
  472.   Returns 1 on success, 0 on failure.
  473.  
  474. long zchki(fn) char *fn;
  475.   Check to see if file with name fn is a regular, readable, existing file,
  476.   suitable for Kermit to send -- not a directory, not a symbolic link, etc.
  477.   Returns:
  478.   -3 if file exists but is not accessible (e.g. read-protected)
  479.   -2 if file exists but is not of a readable type
  480.   -1 on error (e.g. file does not exist, or fn is garbage)
  481.   >= 0 (length of file) if file exists and is readable
  482.  
  483. zchko(fn) char *fn;
  484.   Checks to see if a file of the given name can be created.  Returns:
  485.   -1 if file cannot be created, or on any kind of error.
  486.    0 if file can be created.
  487.  
  488. zchkspa(fn,len) char *f; long len;       *NEW*
  489.   Check to see if there is sufficient space to store the file named fn,
  490.   which is len bytes long.  Returns:
  491.   -1 on error.
  492.    0 if there is not enough space.
  493.    1 if there is enough space.
  494.   If you can't write a function to do this, then just make a dummy that
  495.   always returns 1.  Higher level code will recover from disk-full errors.
  496.   The receiving Kermit uses this function to refuse an incoming file based
  497.   on its size, via the attribute mechanism.
  498.  
  499. zchin(n,c) int n; int *c;
  500.   Get a character from file number n, return it in c (call with &c).
  501.   Returns:
  502.   -1 on failure, including EOF.
  503.    0 on success with character in c.
  504.  
  505. zchout(n,c) int n; char c;
  506.   Write the character c to file number n.  Returns:
  507.   -1 error
  508.    0 OK
  509.  
  510. zclose(n) int n;
  511.   Close file number n.  Returns:
  512.   -1 error
  513.    1 OK
  514.  
  515. zdelet(fn) char *name;  *NEW*
  516.   Attempts to delete the named file.  Returns:
  517.   -1 on error
  518.    0 if file was deleted successfully
  519.  
  520. char *
  521. zgtdir()  *NEW*
  522.   Returns a pointer to the name of the current directory, folder, etc, or a
  523.   NULL pointer if the current directory cannot be determined.  Most Kermit
  524.   versions currently do something like "system(PWDCMD)", but Macintoshes don't
  525.   support system().
  526.  
  527. char *zhome()
  528.   Returns a pointer to a string containing the user's home directory, or NULL
  529.   upon error.
  530.  
  531. zinfill()  *NEW*
  532.   This function is used by the macro zminchar(), which is defined in ckcker.h.
  533.   zminchar() manages its own buffer, and calls zinfill() to fill it whenever
  534.   it becomes empty.  It is only used for sending files, and reads characters
  535.   only from file number ZIFILE.  zinfill() returns -1 upon end of file,
  536.   otherwise it returns the first character from the buffer it just read.
  537.  
  538. zkself()
  539.   Kills the current job, session, process, etc, logs out, disappears.  Used by
  540.   the Kermit server when it receives a BYE command.  On failure, returns -1.
  541.   On success, does not return at all!  This function should not be called
  542.   until all other steps have been taken to close files, etc.
  543.  
  544. zstrip(fn,&fn2) char *fn1, **fn2;
  545.   Strip device and directory, etc, from file specification, leaving only the 
  546.   filename.  For example DUA0:[PROGRAMS]OOFA.C;3 becomes OOFA.C, or
  547.   /usr/fdc/oofa.c becomes oofa.c.  Returns pointer to result in fn2.
  548.  
  549. zltor(fn,fn2) char *fn1, *fn2;
  550.   Local-To-Remote filename translation.  Translates the local filename fn into
  551.   a format suitable for transmission to an arbitrary type of computer, and
  552.   copies the result into the buffer pointed to by fn2.  Translation may involve
  553.   (a) stripping the device and/or directory/path name, (b) converting
  554.   lowercase to uppercase, (c) removing spaces and strange characters, or
  555.   converting them to some innocuous alphabetic character like X, (d)
  556.   discarding or converting extra periods (there should not be more than one).
  557.   Does its best.  Returns no value.  name2 is a pointer to a buffer, furnished
  558.   by the caller, into which zltor() writes the resulting name.  No length
  559.   checking is done.
  560.  
  561. zmail(addr,fn) char *addr, fn;  *NEW*
  562.   Send the local, existing file fn as e-mail to the address addr.  Returns:
  563.   Returns 0 on success
  564.    2 if mail delivered but temp file can't be deleted
  565.   -2 if mail can't be delivered
  566.  
  567. znewn(fn,s) char *fn, **s;
  568.   Transforms the name fn into a filename which is guaranteed to be unique.
  569.   If the file fn does not exist, then the new name will be the same as fn.
  570.   Otherwise, it will be different.  Does its best, returns no value.  New
  571.   name is created in caller's space.  Call like this: znewn(old,&new);.
  572.   The second parameter is a pointer to the new name.  This pointer is set
  573.   by znewn() to point to a static string in its own space.
  574.  
  575. znext(fn) char *fn;
  576.   Copies the next file name from a file list created by zxpand() into the
  577.   string pointed to by fn (see zxpand).  If no more files, then the null
  578.   string is placed there.  Returns the number of files remaining in the list.
  579.  
  580. zopeni(n,fn) int n; char *fn;
  581.   Opens the file named fn for input as file number n.  Returns:
  582.   0 on failure.
  583.   1 on success.
  584.  
  585. *NEW* (zopeno - the second two parameters are new)
  586. zopeno(n,fn,zz,fcb) int n; char *name; struct zattr *zz; struct filinfo *fcb;
  587.   Attempts to open the named file for output as file number n.  zz is a Kermit
  588.   file attribute structure as defined in ckcdeb.h, containing various
  589.   information about the file, including its size, creation date, and so forth.
  590.   This function should attempt to honor as many of these as possible.  fcb is
  591.   a "file control block" in the traditional sense, defined in ckcdeb.h,
  592.   containing information of interest to complicated file systems like VAX/VMS,
  593.   IBM MVS, etc, like blocksize, record length, organization, record format,
  594.   carriage control, disposition (like create vs append), etc.  Returns:
  595.   0 on failure.
  596.   1 on success.
  597.  
  598. zoutdump()  *NEW*
  599.   Dumps an output buffer.  Used with the macro zmchout() defined in ckcker.h.
  600.   Used only with file number ZOFILE, i.e. the file that is being received by
  601.   Kermit during file transfer.  Returns:
  602.   -1 on failure.
  603.    0 on success.
  604.  
  605. zprint(p,fn) char *p, *f;  *NEW*
  606.   Prints the file with name fn on a local printer, with options p.  Returns:
  607.   Returns 0 on success
  608.    3 if file sent to printer but can't be deleted
  609.   -3 if file can't be printed
  610.  
  611. zrename(fn,fn2) char *fn, *fn2;  *NEW*
  612.   Changes the name of file fn to fn2.  Returns:
  613.   -1 on failure.
  614.    0 on success.
  615.  
  616. zrtol(fn,fn2) char *fn, *fn2;
  617.   Remote-To-Local filename translation.  Translates a "standard" filename
  618.   (see zrtol) to a local filename.  For example, in Unix this function
  619.   converts uppercase letters to lowercase.  Does its best, returns no value.
  620.   New name is in string pointed to by fn2.
  621.  
  622. zsattr(xx) struct zattr *xx; {  *NEW*
  623.   Fills in a Kermit file attribute structure for the file which is to be sent,
  624.   namely the currently open ZIFILE.
  625.   Returns:
  626.   -1 on failure.
  627.    0 on success with the structure filled in.
  628.   If any string member is null, then it should be ignored by the caller.
  629.   If any numeric member is -1, then it should be ignored by the caller.
  630.  
  631. zshcmd(s) char *s;
  632.   s contains to pointer to a command to be executed by the host computer's
  633.   shell, command parser, or operating system.  If the system allows the user
  634.   to choose from a variety of command processors (shells), then this function
  635.   should employ the user's preferred shell.  If possible, the user's job
  636.   (environment, process, etc) should be set up to catch keyboard interruption
  637.   signals to allow the user to halt the system command and return to Kermit.
  638.   The command must run in ordinary, unprivileged user mode.
  639.   If possible, this function should return -1 on failure to start the command,
  640.   or else it should return the command's return code, presumably a positive
  641.   value if the command succeeded.
  642.  
  643. zsyscmd(s) char *s;  *NEW*
  644.   s contains to pointer to a command to be executed by the host computer's
  645.   shell, command parser, or operating system.  If the system allows the user
  646.   to choose from a variety of command processors (shells), then this function
  647.   should employ the system standard shell (e.g. /bin/sh for Unix), so that the
  648.   results will always be the same for everybody.  If possible, the user's job
  649.   (environment, process, etc) should be set up to catch keyboard interruption
  650.   signals to allow the user to halt the system command and return to Kermit.
  651.   The command must run in ordinary, unprivileged user mode.
  652.   If possible, this function should return -1 on failure to start the command,
  653.   or else it should return the command's return code, presumably a positive
  654.   value if the command succeeded.
  655.  
  656. zsinl(n,s,x) int n, x; char *s;  *NEW*
  657.   Reads a line from file number n.
  658.   Writes the line into the address s provided by the caller.
  659.   Writing terminates when newline is read, but with newline discarded.
  660.   Writing also terminates upon EOF or if length x is exhausted.
  661.   Returns:
  662.   -1 on EOF or error.
  663.   0 on success.
  664.  
  665. zsout(n,s) int n; char *s;
  666.   Writes the string s out to file number n.  Returns:
  667.   -1 on failure.
  668.    0 on success.
  669.  
  670. zsoutl(n,s) int n; char *s;
  671.   Writes the string s out to file number n and adds a line (record) terminator 
  672.   (boundary) appropriate for the system and the file format.
  673.   Returns:
  674.   -1 on failure.
  675.    0 on success.
  676.  
  677. zsoutx(n,s,x) int n, x; char *s;
  678.   Writes exactly x characters from string s to file number n.  If s has
  679.   fewer than x characters, then the entire string s is written.  Returns:
  680.   -1 on error.
  681.   >= 0 on success, the number of characters actually written.
  682.  
  683. zstime(f,yy,x) char *f; struct zattr *yy; int x;  *NEW*
  684.   Sets the creation date of an existing file, or compares a file's creation
  685.   date with a given date.  Call with:
  686.   f  = pointer to name of existing file.
  687.   yy = pointer to a Kermit file attribute structure in which yy->date.val
  688.        is a date of the form yyyymmdd hh:mm:ss, e.g. 19900208 13:00:00, which
  689.        is to be used for setting the date.
  690.   x  = is a function code: 0 means to set the file's creation date as given.
  691.        1 means compare the given date with the file creation date.      
  692.   Returns:
  693.   -1 on any kind of error.
  694.    0 if x is 0 and the file date was set successfully.
  695.    0 if x is 1 and date from attribute structure > file creation date.
  696.    1 if x is 1 and date from attribute structure <= file creation date.
  697.  
  698. VOID
  699. zstrip(name,name2) char *name, **name2;  *NEW*
  700.   Strips pathname from filename "name".  Constructs the resulting string
  701.   in a static buffer in its own space and returns a pointer to it in name2.
  702.   Also strips device name, file version numbers, and other "non-name" material.
  703.  
  704. *NEW* (zxcmd - arguments are new, writing to a command is new)
  705. zxcmd(n,s) char *s;
  706.   Runs a system command so its output can be accessed as if it were file n.
  707.   The command is run in ordinary, unprivileged user mode.
  708.   If n is ZSTDIO or ZCTERM, returns -1.
  709.   If n is ZIFILE or ZRFILE, then Kermit reads from the command, otherwise
  710.   Kermit writes to the command.  Returns 0 on error, 1 on success.
  711.  
  712. zxpand(fn) char *fn;
  713.   Expands a wildcard string into an array of strings.
  714.   Returns the number of files that match fn1, with data structures set up
  715.   so that first filename (if any) will be returned by the next znext() call.
  716.   If no files match, or if there is any kind of error, zxpand returns 0.
  717.  
  718. xsystem(cmd) char *cmd;
  719.   Executes the system command without redirecting any of its i/o, similar
  720.   (well, identical) to system() in Unix.  But before passing the command to
  721.   the system, xsystem() ensures that all privileges are turned off, so that
  722.   the system command will execute in ordinary unprivileged user mode.
  723.  
  724. B.1.5 Security/Privilege Functions (all *NEW*)
  725.  
  726. These functions are used by C-Kermit to adapt itself to operating systems
  727. where the program can be made to run in a "privileged" mode.  C-Kermit
  728. should NOT read and write files or start subprocesses as a privileged program.
  729. This would present a serious threat to system security.  The security package
  730. has been installed to prevent such security breaches by turning off the
  731. program's special privileges at all times except when they are needed.
  732.  
  733. In UNIX, the only need Kermit has for privileged status is access to the UUCP
  734. lockfile directory, in order to read, create, and destroy lockfiles, and to
  735. open communication devices that are normally protected against the user.
  736. Therefore, privileges should only be enabled for these operations and disabled
  737. at all other times.  This relieves the programmer of the responsibility of
  738. putting expensive and unreliable access checks around every file access and
  739. subprocess creation.
  740.  
  741. Strictly speaking, these functions are not required in all C-Kermit
  742. implementations, because their use (so far, at least) is internal to the group
  743. 3 modules.  However, they should be included in all C-Kermit implementations
  744. for operating systems that support the notion of a privileged program (UNIX,
  745. RSTS/E, what else?).
  746.  
  747. priv_ini()  *NEW*
  748.   Determine whether the program is running in privileged status.  If so,
  749.   turn off the privileges, in such a way that they can be turned on again
  750.   when needed.  Called from sysinit() at program startup time.  Returns:
  751.     0 on success
  752.     nonzero on failure, in which case the program should halt immediately.
  753.  
  754. priv_on()  *NEW*
  755.   If the program is not privileged, this function does nothing.  If the
  756.   program is privileged, this function returns it to privileged status.
  757.   priv_ini() must have been called first.  Returns:
  758.     0 on success
  759.     nonzero on failure
  760.  
  761. priv_off()  *NEW*
  762.   Turns privileges off (if they are on) in such a way that they can be
  763.   turned back on again.  Returns:
  764.     0 on success
  765.     nonzero on failure
  766.  
  767. priv_can()  *NEW*
  768.   Turns privileges off in such a way that they cannot be turned back on.
  769.   Returns:
  770.     0 on success
  771.     nonzero on failure
  772.  
  773. priv_chk()  *NEW*
  774.   Attempts to turns privileges off in such a way that they can be turned on
  775.   again later.  Then checks to make sure that they were really turned off.
  776.   If they were not really turned off, then they are cancelled permanently.
  777.  
  778.  
  779. B.2.  Console-Related Functions.
  780.  
  781. These relate to the program's "console", or controlling terminal, i.e. the
  782. terminal that the user is logged in on and types commands at, or on a PC or
  783. workstation, the actual keyboard and screen.
  784.  
  785. int
  786. conbin(esc) char esc;
  787.   Puts the console into "binary" mode, so that Kermit's command parser can
  788.   control echoing and other treatment of characters that the user types.
  789.   esc is the character that will be used to get Kermit's attention during
  790.   packet mode; puts this in a global place.  Sets the ckxech variable.
  791.   Returns:
  792.   -1 on error.
  793.    0 on success.
  794.  
  795. int
  796. concb(esc) char esc;
  797.   Put console in "cbreak" (single-character wakeup) mode.  That is, ensure
  798.   that each console character is available to the program immediately when the
  799.   user types it.  Otherwise just like conbin().  Returns:
  800.   -1 on error.
  801.    0 on success.
  802.  
  803. int
  804. conchk()
  805.   Returns a number, 0 or greater, the number of characters waiting to be read
  806.   from the console, i.e. the number of characters that the user has typed that
  807.   have not been read yet.
  808.  
  809. int
  810. congks(timo) int timo;   *NEW*
  811.   Get Keyboard Scancode.  Reads a keyboard scan code from the physical console
  812.   keyboard.  If the timo parameter is greater than zero, then times out and
  813.   returns -2 if no character appears within the given number of seconds.  Upon
  814.   any other kind of error, returns -1.  Upon success returns a scan code,
  815.   which may be any positive integer.  For situations where scan codes cannot
  816.   be read (for example, when an ASCII terminal is used as the job's
  817.   controlling terminal), this function is identical to coninc(), i.e. it
  818.   returns an 8-bit character value.  congks() is for use with workstations
  819.   whose keyboards have Alternate, Command, Option, and similar modifier keys,
  820.   and Function keys that generate codes greater than 255.
  821.  
  822. int
  823. congm()
  824.   Console get modes.  Gets the current console terminal modes and saves them 
  825.   so that conres() can restore them later.  Returns 1 if it got the modes OK,
  826.   0 if it did nothing (e.g. because Kermit is not connected with any terminal),
  827.   -1 on error.
  828.  
  829. int
  830. coninc(timo) int timo;
  831.   Console Input Character.  Reads a character from the console.  If the timo
  832.   parameter is greater than zero, then coninc() times out and returns -2 if no
  833.   character appears within the given number of seconds.  Upon any other kind
  834.   of error, returns -1.  Upon success, returns the character itself, with a
  835.   value in the range 0-255 decimal.
  836.  
  837. VOID
  838. conint(f,s) SIGTYP (*f)(), (*s)();  *NEW*
  839.   Sets the console to generate an interrupt if the user types a keyboard
  840.   interrupt character, and to transfer control the signal-handling function f.
  841.   For systems with job control, s is the address of the function that suspends
  842.   the job.  Sets the global variable "backgrd" to zero if Kermit is running in
  843.   the foreground, and to nonzero if Kermit is running in the background.
  844.   See ckcdeb.h for the definition of SIGTYP.  No return value.
  845.  
  846. VOID
  847. connoi()
  848.   Console no interrupts.  Disable keyboard interrupts on the console.
  849.   No return value.
  850.  
  851. int
  852. conoc(c) char c;
  853.   Write character c to the console terminal.  Returns:
  854.   0 on failure, 1 on success.
  855.  
  856. int
  857. conol(s) char *s;
  858.   Write string s to the console.  Returns -1 on error, 0 or greater on
  859.   success.
  860.  
  861. int
  862. conola(s) char *s[]; {
  863.   Write an array of strings to the console.  Returns -1 on error, 0 or greater
  864.   on success.
  865.  
  866. int
  867. conoll(s) char *s;
  868.   Write string s to the console, followed by the necessary line termination
  869.   characters to put the console cursor at the beginning of the next line.
  870.   Returns -1 on error, 0 or greater on success.
  871.  
  872. int
  873. conres()
  874.   Restore the console terminal to the modes obtained by congm().  Returns:
  875.   -1 on error, 0 on success.
  876.  
  877. int
  878. conxo(x,s) int x; char *s;
  879.   Write x characters from string s to the console.  Returns 0 or greater on
  880.   success, -1 on error.
  881.  
  882. B.3 - Communication Device Functions
  883.  
  884. The communication device is the device used for terminal emulation and file
  885. transfer.  It may or may not be the same device as the console, and it may
  886. or may not be a terminal device (it could also be a network device).  For
  887. brevity, the communication device is referred to here as the "tty".  When the
  888. communication device is the same as the console device, Kermit is said to be
  889. in remote mode.  When the two devices are different, Kermit is in local mode.
  890.  
  891. int
  892. ttchk()
  893.   Returns the number of characters that have arrived at the communication
  894.   device but have not yet been read.  If communication input is buffered
  895.   (and it should be), this is the sum of the number of unread characters in
  896.   Kermit's buffer PLUS the number of unread characters in the operating
  897.   system's internal buffer.
  898.  
  899. int
  900. ttclos()
  901.   Closes the communication device (tty or network).  If there were any kind of
  902.   exclusive access locks connected with the tty, these are released.  If the
  903.   tty has a modem connection, it is hung up.  For true tty devices, the
  904.   original tty device modes are restored.  Returns:
  905.   -1 on failure.
  906.    0 on success.
  907.  
  908. int
  909. ttflui()
  910.   Flush communications input buffer.  If any characters have arrived but have
  911.   not yet been read, discard these characters.  If communications input is
  912.   buffered by Kermit (and it should be), this function flushes Kermit's buffer
  913.   as well as the operating system's internal input buffer.
  914.  
  915. Returns:
  916.   -1 on failure.
  917.    0 on success.
  918.  
  919. int
  920. ttfluo()  *NEW*
  921.   Flush tty output buffer.  If any characters have been written but not
  922.   actually transmitted (e.g. because the system has been flow-controlled),
  923.   remove them from the system's output buffer.  (Note, this function is
  924.   not actually used, but it is recommended that all C-Kermit programmers
  925.   add it for future use, even if it is only a dummy function that returns 0
  926.   always.)
  927.  
  928. int
  929. ttgmdm()  *NEW*
  930.   Looks for the modem signals CTS, DSR, and CTS, and returns those that are
  931.   on in as its return value, in a bit mask as described for ttwmdm,
  932.   in which a bit is on (1) or off (0) according to whether the corresponding
  933.   signal is on (asserted) or off (not asserted).  Return values:
  934.   -3 Not implemented
  935.   -2 if the line does not have modem control
  936.   -1 on error
  937.   >= 0 on success, with bit mask containing the modem signals.
  938.  
  939. long
  940. ttgspd()  *NEW*
  941.   Returns the current tty speed, or -1 if it is not known or if the tty is
  942.   really a network, or upon any kind of error.  On success, the speed returned
  943.   is the actual number of bits per second, like 1200, 9600, 19200, etc.
  944.  
  945. int
  946. tthang()
  947.   Hang up the current tty device.  For real tty devices, turn off DTR for
  948.   about 1/3-1/2 second.  If the tty is really a network connection, close it.
  949.   Returns:
  950.   -1 on failure.
  951.    0 if it does not even try to hang up.
  952.    1 if it believes it hung up successfully.
  953.  
  954. VOID
  955. ttimoff()  *NEW*
  956.   Turns off all pending timer interrupts.
  957.  
  958. int
  959. ttinc(timo) int timo;  *NEW* (function is old, return codes are new)
  960.   Reads one character from the communication device.  If timo is greater than
  961.   zero, wait the given number of seconds and then time out if no character
  962.   arrives, otherwise wait forever for a character.  Returns:
  963.   -3 internal error (e.g. tty modes set wrong)
  964.   -2 communications disconnect
  965.   -1 timeout or other error
  966.   >= 0 the character that was read.
  967.   It is HIGHLY RECOMMENDED that ttinc() be internally buffered so that calls
  968.   to it are relatively inexpensive.  If it is possible to to implement ttinc()
  969.   as a macro, all the better, for example something like:
  970.  
  971.   #define ttinc(t) ( (--txbufn >= 0) ? txbuf[ttbufp++] : txbufr(t) )
  972.  
  973.   (see description of txbufr() below)
  974.  
  975. *NEW* (ttinl - 5th arg, requirement not to destroy read-ahead characters)
  976. int
  977. ttinl(dest,max,timo,eol,start) int max,timo; CHAR *dest, eol, start; 
  978.   ttinl() is Kermit's packet reader.  Reads a packet from the tty device, or
  979.   up to max characters, whichever occurs first.  A line is a string of
  980.   characters starting with the start character up to and including the
  981.   character given in eol.  If timo is greater than zero, then this function
  982.   times out if the eol character is not encountered within the given number of
  983.   seconds.  The characters that were input are copied into "dest" with their
  984.   parity bits stripped if parity is not none.  The first character copied into
  985.   dest should be the start character, and the last should be the eol
  986.   character, followed by a null (0) character.  Returns the number of
  987.   characters read.  Characters after the eol must be available upon the next
  988.   call to this function.  (If they are discarded, sliding windows will not
  989.   work.)  Optionally, ttinl() can sense the parity of incoming packets.  If it
  990.   does this, then it should set the global variable ttprty accordingly.  This
  991.   function should be coded to be as efficient as possible, since it is at the
  992.   "inner loop" of packet reception.  Returns:
  993.    -2 Interrupted from keyboard.
  994.    -1 Timeout or other error.
  995.    >= 0 on success, the number of characters that were actually read
  996.         and placed in the dest buffer, not counting the trailing null.
  997.   NOTE: This description is somewhat obsolete.  To implement "Doomsday
  998.   Kermit", ttinl() (at least for UNIX and VMS) has got its fingers even more
  999.   deeply into the packet format.  I would like to get rid of this function
  1000.   entirely, and move all packet-related operations to rpack() where they
  1001.   belong.  rpack() would simply call ttinc() to get each character.  But
  1002.   that demands that ttinc() be efficient and fully buffered, going to the
  1003.   operating system with relative infrequency.  See ttinc() and txbufr().
  1004.  
  1005. int
  1006. ttoc(c) char c;
  1007.   Outputs the character c to the communication line.  If the operation fails
  1008.   to complete within two seconds, this function returns -1.  Otherwise it
  1009.   returns the number of characters actually written to the tty (0 or 1).  This
  1010.   function should only used for interactive, character-mode operations, like
  1011.   terminal connection, script execution, dialer i/o, where the overhead of the
  1012.   signals and alarms does not create a bottleneck.
  1013.  
  1014. int
  1015. ttol(s,n) int n; char *s;
  1016.   Kermit's packet writer.  Writes the first n characters of the "line" pointed
  1017.   to by s.  Returns:
  1018.   -1 on error.
  1019.   >= 0 on success, the actual number of characters written.
  1020.  
  1021. *NEW* (ttopen - negative value for modem = network, new timeout feature)
  1022. int
  1023. ttopen(ttname,lcl,modem,timo) char *ttname; int *lcl, modem, timo;
  1024.   Opens a tty device, if it is not already open.  ttopen must check to make
  1025.   sure the SAME device is not already open; if it is, ttopen returns 
  1026.   successfully without doing anything.  If a DIFFERENT device is currently
  1027.   open, ttopen() must call ttclos() to close it before opening the new one.
  1028. Parameters:
  1029.     ttname: character string - device name or network host name.
  1030.     lcl:   If called with lcl < 0, sets value of lcl as follows:
  1031.       0: the terminal named by ttname is the job's controlling terminal.
  1032.       1: the terminal named by ttname is not the job's controlling terminal.
  1033.       If the line is already open, or if the requested line can't
  1034.       be opened, then lcl remains (and is returned as) -1.
  1035.     modem:
  1036.       Less than zero: this is the negative of the network type,
  1037.       and ttname is a network host name.  Network types (from ckcnet.h):
  1038.         NET_TCPB 1   TCP/IP Berkeley (socket)  (implemented in ckutio.c)
  1039.         NET_TCPA 2   TCP/IP AT&T (streams)     (not yet implemented)
  1040.         NET_DEC  3   DECnet                    (not yet implemented)
  1041.       Zero or greater: ttname is a terminal device name.    
  1042.       Zero means a direct connection (don't use modem signals).
  1043.       Positive means use modem signals depending on the current setting
  1044.       of ttcarr ( see ttscarr() ).
  1045.     timo:
  1046.       > 0: number of seconds to wait for open() to return before timing out.
  1047.       <=0: no timer, wait forever (e.g. for incoming call).
  1048.     For real tty devices, ttopen() attempts to gain exclusive access to the
  1049.     tty device, for example in UNIX by creating a "lockfile" (in other
  1050.     operating systems, like VMS, exclusive access probably requires no special
  1051.     action).
  1052.   Side effects:
  1053.     Copies its arguments and the tty file descriptor to global variables that
  1054.     are available to the other tty-related functions, with the lcl value
  1055.     altered as described above.   Gets all parameters and settings associated
  1056.     with the line and puts them in a global area, so that they can be restored
  1057.     by ttres(), e.g. when the device is closed.
  1058.   Returns:
  1059.     0 on success
  1060.    -5 if device is in use
  1061.    -4 if access to device is denied
  1062.    -3 if access to lock mechanism denied
  1063.    -2 upon timeout waiting for device to open
  1064.    -1 on other error
  1065.  
  1066. int
  1067. ttpkt(speed,flow,parity) long speed; int flow, parity;
  1068.   Puts the currently open tty device into the appropriate modes for
  1069.   transmitting Kermit packets.  The arguments are interpreted as follows:
  1070.   speed: if speed > -1, and the device is a true tty device, and Kermit is in
  1071.          local mode, ttpkt also sets the speed.
  1072.   flow:  if in the range 0-3, ttpkt selects the corresponding type of flow
  1073.          control.  Currently 0 is defined as no flow control, 1 is Xon/Xoff,
  1074.          and no other types are defined.  If (and this is a horrible hack, but
  1075.          it goes back many years and will be hard to eradicate) flow is 4,
  1076.          then the appropriate tty modes are set for modem dialing, a special
  1077.          case in which we talk to a modem-controlled line without requiring
  1078.          carrier.  If flow is 5, then we require carrier.
  1079.   parity:  This is simply copied into a global variable so that other
  1080.          functions (like ttinl, ttinc, etc) can use it.
  1081.   Side effects: Copies its arguments to global variables, flushes the terminal
  1082.          device input buffer.  
  1083.   Returns:
  1084.    -1 on error.
  1085.     0 on success.
  1086.  
  1087. int
  1088. ttres()
  1089.   Restores the tty device to the modes and settings that were in effect at
  1090.   the time it was opened (see ttopen).  Returns:
  1091.   -1 on error.
  1092.    0 on success.
  1093.  
  1094. int
  1095. ttscarr(carrier) int carrier;  *NEW*
  1096.   Copies its argument to a variable that is global to the other tty-related
  1097.   functions, and then returns it.  The values for carrier are defined in
  1098.   ckcdeb.h: CAR_ON, CAR_OFF, CAR_AUTO.  ttopen(), ttpkt(), and ttvt() use this
  1099.   variable when deciding how to open the tty device and what modes to select.
  1100.   The meanings are these:
  1101.   CAR_OFF:  Ignore carrier at all times.
  1102.   CAR_ON:   Require carrier at all times, except when dialing.
  1103.             This means, for example, that ttopen() could hang forever waiting 
  1104.             for carrier if it is not present.
  1105.   CAR_AUTO: If the modem type is zero (i.e. the connection is direct), this
  1106.             is the same as CAR_OFF.  If the modem type is positive, then heed
  1107.             carrier during CONNECT (ttvt mode), but ignore it at other times
  1108.             (packet mode, during SET LINE, etc).  Compatible with pre-5A
  1109.             versions of C-Kermit.  This should be the default carrier mode.
  1110.   Kermit's DIAL command ignores the carrier setting, but ttopen(), ttvt(), and
  1111.   ttpkt() all honor the carrier option in effect at the time they are called.
  1112.   None of this applies to remote mode (the tty device is the job's controlling
  1113.   terminal) or to network host connections (modem type is negative).
  1114.  
  1115. int
  1116. ttsndb()
  1117.   Send a BREAK signal on the tty device.  On a real tty device, send a real
  1118.   BREAK lasting approximately 275 milliseconds.  If this is not possible,
  1119.   simulate a BREAK by (for example) dropping down some very low baud rate,
  1120.   like 50, and sending a bunch of null characters.  On a network connection,
  1121.   do the appropriate network protocol for BREAK.  Returns:
  1122.   -1 on error.
  1123.    0 on success.
  1124.  
  1125. int
  1126. ttsndlb() *NEW*
  1127.   Like ttsndb(), but sends a "Long BREAK" (approx 1.5 seconds).
  1128.   For network connections, it is identical to ttsndb().
  1129.   Currently, this function is used only if CK_LBRK is defined (as it is
  1130.   for UNIX and VAX/VMS).
  1131.  
  1132. int
  1133. ttsspd(cps) int cps;  *NEW* (argument is now cps instead of bps)
  1134.   For real tty devices only, set the device transmission speed to (note
  1135.   carefully) ten times the argument.  The argument is in characters per
  1136.   second, but transmission speeds are in bits per second.  cps are used rather
  1137.   than bps because high speeds like 38400 are not expressible in a 16-bit int
  1138.   but longs cannot be used for other reasons too complicated to explain.  If
  1139.   the argument is 7, then the bps is 75, not 70.  If the argument is 888, this
  1140.   is a special code for 75/1200 split-speed operation (75 bps out, 1200 bps
  1141.   in).  Returns:
  1142.   -1 on error, meaning the requested speed is not valid or available.
  1143.   >= 0 on success (don't try to use this value for anything).
  1144.  
  1145. int
  1146. ttvt(speed,flow) long speed; int flow;
  1147.   Puts the currently open tty device into the appropriate modes for terminal
  1148.   emulation.  The arguments are interpreted as in ttpkt().  Side effects:
  1149.   ttvt() stores its arguments in global variables, and sets a flag that it has
  1150.   been called so that subsequent calls can be ignored so long as the arguments
  1151.   are the same as in the last effective call.  Other functions, such as
  1152.   ttopen(), ttclose(), ttres(), ttvt(), etc, that change the tty device in any
  1153.   way must unset this flag.  In UNIX Kermit, this flag is called tvtflg.
  1154.  
  1155. int
  1156. ttwmdm(mdmsig,timo) int mdmsig, timo;  *NEW*
  1157.   Waits up to timo seconds for all of the given modem signals to appear.
  1158.   mdmsig is a bit mask, in which a bit is on (1) or off (0) according to
  1159.   whether the corresponding signal is to be waited for.  These symbols are
  1160.   defined in ckcdeb.h:
  1161.      BM_CTS (bit 0) means wait for Clear To Send 
  1162.      BM_DSR (bit 1) means wait for Data Set Ready
  1163.      BM_DCD (bit 2) means wait for Carrier Detect
  1164.   Returns:
  1165.     -3 Not implemented.
  1166.     -2 This line does not have modem control.
  1167.     -1 Timeout: time limit exceeded before all signals were detected.
  1168.      1 Success.
  1169.  
  1170. int
  1171. ttxin(n,buf) int n; CHAR *buf;
  1172.   (note: CHAR is used throughout this program, and should be typedef'd to
  1173.   unsigned char if your C compiler supports it.  See ckcdeb.h.)
  1174.   Read x characters from the tty device into the specified buf, stripping
  1175.   parity if parity is not none.  This call waits forever, there is no timeout.
  1176.   This function is designed to be called only when you know that at least x
  1177.   characters are waiting to be read (as determined, for example, by ttchk()). 
  1178.   This function should use the same buffer as ttinc().
  1179.  
  1180. int
  1181. txbufr(timo) int timo; *NEW*
  1182.   Read characters into the interal communications input buffer.  timo is a
  1183.   timeout interval, in seconds.  0 means no timeout, wait forever.  Called by
  1184.   ttinc() (and possibly ttxin() and ttinl()) when the communications input
  1185.   buffer is empty.  The buffer should be called ttxbuf[], its length is
  1186.   defined by the symbol TXBUFL.  The global variable txbufn is the number of
  1187.   characters available to be read from ttxbuf[], and txbufp is the index of
  1188.   the next character to be read.  Should not be called if txbufn > 0, in which
  1189.   case the buffer does not need refilling.  This routine returns:
  1190.    -2    Communications disconnect
  1191.    -1    Timeout
  1192.    >= 0  A character (0 - 255), the first character that was read, with
  1193.          the variables txbufn and txbufp set appropriately.
  1194.   NOTE: Currently this routine is used internally only by the UNIX and VMS
  1195.   versions.  The aim is to make it available to all versions so there is one
  1196.   single coherent and efficient way of reading from the communications device
  1197.   or network.
  1198.  
  1199. B.4 - Miscellaneous system-dependent functions.
  1200.  
  1201. VOID
  1202. ztime(s) char **s;
  1203.   Write the date/time string for the current date and time into the string
  1204.   pointed to by s.  This string should be in the fixed-field format associated
  1205.   with the C language "asctime()" function, like: "Sun Sep 16 13:23:45 1973\n"
  1206.   so that callers of this function can extract the different fields.
  1207.   ztime() has no return value.
  1208.     
  1209. int
  1210. gtimer()
  1211.   Returns the current value of the elapsed time counter in seconds (see
  1212.   rtimer), or 0 on any kind of error.
  1213.  
  1214. int
  1215. msleep(m) int m;
  1216.   Sleeps (pauses, does nothing) for m milliseconds (a millisecond is one
  1217.   thousandth of a second).  Returns:
  1218.   -1 on failure.
  1219.    0 on success.
  1220.  
  1221. VOID
  1222. rtimer()
  1223.   Sets the elapsed time counter to zero.  If you want to time how long an
  1224.   operation takes, call rtimer() when it starts and gtimer when it ends.
  1225.   rtimer() has no return value.
  1226.  
  1227. int
  1228. sysinit()
  1229.   Does whatever needs doing upon program start.  In particular, if the
  1230.   program is running in any kind of privileged mode, turns off the privileges
  1231.   (see priv_ini()).  Returns:
  1232.   -1 on error.
  1233.    0 on success.
  1234.  
  1235. int
  1236. syscleanup()
  1237.   Does whatever needs doing upon program exit.  Returns:
  1238.   -1 on error.
  1239.    0 on success.
  1240.  
  1241. int
  1242. psuspend()   *NEW*
  1243.   Suspends the Kermit process, puts it in the background so it can be
  1244.   continued ("foregrounded") later.  Returns:
  1245.   -1 if this function is not supported.
  1246.    0 on success.
  1247.  
  1248. GROUP 4 - Network Support.
  1249.  
  1250. As of version 5A, C-Kermit includes support for several networks.  Originally,
  1251. this was just worked into the ttopen(), ttclos(), ttinc(), ttinl(), and
  1252. similar routines in CKUTIO.C.  However, this made it impossible to share this
  1253. code with non-UNIX versions, like VMS.
  1254.  
  1255. As of edit 168, this support has been separated out into its own module and
  1256. header file, CKCNET.C and CKCNET.H.  The routines and variables in this module
  1257. fall into two categories: (1) support for specific network packages like
  1258. SunLink X.25 and TGV MultiNet, and (2) support for specific network virtual
  1259. terminal protocols like CCITT X.3 and TCP/IP telnet.  Category (1) functions
  1260. are analogs to the tt*() functions, and have names like netopen, netclos,
  1261. nettinc, etc.  Group I and II modules do not (and must not) know anything
  1262. about these functions -- they continue to call the old Group III functions
  1263. (ttopen, ttinc, etc).  Category (2) functions are protocol specific and have
  1264. names prefixed by a protocol identifier, like tn for telnet x25 for X.25.
  1265.  
  1266. CKCNET.H contains prototypes for all these functions, as well as symbol
  1267. definitions for network types, protocols, and network- and protocol- specific
  1268. symbols, as well as #includes for the header files necessary for each network
  1269. and protocol.
  1270.  
  1271. The following functions are to be provided for networks that do not use normal
  1272. system i/o (open, read, write, close):
  1273.  
  1274. int
  1275. netopen()
  1276.   To be called from within ttopen() when a network connection is requested.
  1277.   Calling conventions and purpose same as Group III ttopen().
  1278.  
  1279. int
  1280. netclos()
  1281.   To be called from within ttclos() when a network connection is being closed.
  1282.   Calling conventions and purpose same as Group III ttclos().
  1283.  
  1284. int
  1285. nettchk()
  1286.   To be called from within ttchk().
  1287.   Calling conventions and purpose same as Group III ttchk().
  1288.  
  1289. int
  1290. netflui()
  1291.   To be called from within ttflui().
  1292.   Calling conventions and purpose same as Group III ttflui().
  1293.  
  1294. int
  1295. netbreak()
  1296.   To send a network break (attention) signal.
  1297.   Calling conventions and purpose same as Group III ttsndbrk().
  1298.  
  1299. int
  1300. netinc()
  1301.   To get a character from the network.
  1302.   Calling conventions same as Group III ttsndbrk().
  1303.  
  1304. int
  1305. nettoc()
  1306.   Send a "character" (byte) to the network.
  1307.   Calling conventions same as Group III ttoc().
  1308.  
  1309. int
  1310. nettol()
  1311.   Send a "line" (sequence of bytes) to the network.
  1312.   Calling conventions same as Group III ttol().
  1313.  
  1314. Conceivably, some systems support network connections simply by letting
  1315. you open a device of a certain name and letting you do i/o to it.  Others
  1316. (like the Berkeley sockets TCP/IP library on UNIX) require you to open the
  1317. connection in a special way, but then do normal i/o (read, write).  In such
  1318. a case, you would use netopen(), but you would not use nettinc, nettoc, etc.
  1319.  
  1320. TGV MultiNET on VAX/VMS has its own set of functions for all network
  1321. operations, so in that case the full range of netxxx() functions is used.
  1322.  
  1323. The technique is to put a test in each corresponding ttxxx() function to
  1324. see if a network connection is active (or is being requested), test for which
  1325. kind of network it is, and if necessary route the call to the corresponding
  1326. netxxx() function.  The netxxx() function must also contain code to test for
  1327. the network type, which is available via the global variable ttnet.
  1328.  
  1329. TELNET SUPPORT:
  1330.  
  1331. The telnet protocol is supported by the following variables and routines:
  1332.  
  1333. (global) int tn_init: nonzero if telnet protocol initialized, zero otherwise.
  1334.  
  1335. int
  1336. tn_init()
  1337.   Initialize the telnet protocol (send initial options).
  1338.  
  1339. int
  1340. tn_sopt()
  1341.   Send a telnet option.
  1342.  
  1343. int
  1344. tn_doop()
  1345.   Receive and act on a telnet option from the remote.
  1346.  
  1347. int
  1348. tn_sttyp()
  1349.   Send terminal type using telnet protocol.
  1350.  
  1351. X.25 SUPPORT:
  1352.  
  1353. These are presently specific to SunLink X.25, but it is hoped that they can
  1354. be integrated better with the functions above, and made more general so they
  1355. could be used, for instance, with VAX PSI.
  1356.  
  1357. x25diag()
  1358.   Read and print X.25 diagnostic
  1359.  
  1360. x25oobh()
  1361.   X.25 out of band signal handler
  1362.  
  1363. x25intr()
  1364.   Send X.25 interrupt packet
  1365.  
  1366. x25reset()
  1367.   Reset X.25 virtual circuit
  1368.  
  1369. x25clear()
  1370.   Clear X.25 virtual circuit
  1371.  
  1372. x25stat()
  1373.   X.25 status
  1374.  
  1375. setqbit()
  1376.   Set X.25 Q-bit
  1377.  
  1378. resetqbit()
  1379.   Reset X.25 Q-bit
  1380.  
  1381. x25xin()
  1382.   Read n characters from X.25 circuit.
  1383.  
  1384. x25inl()
  1385.   Read a Kermit packet from X.25 circuit.
  1386.  
  1387.  
  1388. GROUP 5 - Formatted Screen Support
  1389.  
  1390. So far, this is used only for the fullscreen local-mode file transfer display.
  1391. In the future, it might be extended to other uses.  The fullscreen display
  1392. code is in and around the routine screenc() in ckuusx.c.
  1393.  
  1394. In the UNIX version, we use the curses library, plus one call from the termcap
  1395. library.  In other versions (OS/2, VMS, etc) we insert dummy routines that
  1396. have the same names as curses routines.  So far, there are two methods for
  1397. simulating curses routines:
  1398.  
  1399.  1. In VMS, we use the Screen Management Library (SMG), and insert stubs
  1400.     to convert curses calls into SMG calls.
  1401.  
  1402.  2. In OS/2 and AOS/VS, we use the MYCURSES code, in which the stub routines
  1403.     actually emit the appropriate escape sequences themselves.
  1404.  
  1405. Here are the stub routines:
  1406.  
  1407. tgetent(char *buf, char *term)
  1408.   Arguments are ignored.  Returns 1 if the user has a supported terminal
  1409.   type, 0 otherwise.  Sets a global variable (for example, "isvt52" or
  1410.   "isdasher") to indicate the terminal type.
  1411.  
  1412. move(int row, int col)
  1413.   Sends the escape sequence to position the cursor at the indicated row
  1414.   and column.  The numbers are 0-based, e.g. the home position is 0,0.
  1415.  
  1416. clear()
  1417.   Sends the escape sequence to clear the screen.
  1418.  
  1419. clrtoeol()
  1420.   Sends the escape sequence to clear from the current cursor position to
  1421.   the end of the line.
  1422.  
  1423. In the MYCURSES case, code must be added to each of the last three routines
  1424. to emit the appropriate escape sequences for a new terminal type.
  1425.  
  1426. (End of CKAPLM.DOC)
  1427.  
  1428.